package top.lingchen.spring5.testdemo;

import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import top.lingchen.spring5.Book;
import top.lingchen.spring5.Orders;
import top.lingchen.spring5.User;

/**
 * @Author 凌宸
 * @create 2021-11-28 下午 4:06
 * @Description
 * @Version 1.0
 */
public class TestSpring5 {

    @Test
    public void testAdd(){
        // 1. 加载 Spring 配置文件
        ApplicationContext context = new ClassPathXmlApplicationContext("bean1.xml");
        // 2. 获取配置创建的对象
        User user = context.getBean("user", User.class);
        System.out.println(user); // top.lingchen.spring5.User@27f723
        user.add(); // add().....
    }

    @Test
    public void testBook(){
        // 1. 加载 Spring 配置文件
        ApplicationContext context = new ClassPathXmlApplicationContext("bean1.xml");
        // 2. 获取配置创建的对象
        Book book = context.getBean("book", Book.class);
        System.out.println(book); // Book{name='深入浅出SpringBoot2.x', author='杨开振'}
    }

    @Test
    public void testOrders(){
        // 1. 加载 Spring 配置文件
        ApplicationContext context = new ClassPathXmlApplicationContext("bean1.xml");
        // 2. 获取配置创建的对象
        Orders orders = context.getBean("orders", Orders.class);
        System.out.println(orders); // Orders{orderName='电脑', address='China'}
    }

}
